package service;

import admin.Admin;

import utils.DbUtils;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Xu,
 * @data 2021/3/5，
 * @time 12:07
 */
public class AdminService {
    public boolean login(String username, String password){
        if(username == null || password == null) {
            return false;
        }
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        List<Admin> admins = null;
        try{
            conn = DbUtils.getConnection();
            String sql = "select * from admin where username = ? and password = ?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1,username);
            pstmt.setString(2,password);
            rs = pstmt.executeQuery();
            return rs.next();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            DbUtils.close(rs,pstmt,conn);
        }
        return false;
    }
}
